﻿using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using deviceManage.Tools;
using Microsoft.AspNetCore.Mvc;

namespace deviceManage.Filters
{
    public class CheckLoginAttribute : Attribute, IActionFilter
    {
        public void OnActionExecuted(ActionExecutedContext context)
        {
            
        }

        public void OnActionExecuting(ActionExecutingContext context)
        {
            string keyId = context.HttpContext.Session.GetString(WebContext.SESSION_KEY_USER_ID);
            if (string.IsNullOrWhiteSpace(keyId)) //跳转到登录页面
            {
                context.Result = new RedirectResult("/login");
            }
        }
    }
}
